<!--
//**************************************************************************
//
//            (C) Okulov Rostislav, 2011
//
//**************************************************************************

/*
 ***************************************************************************
 *                                                                         *
 *   This source is free software; you can redistribute it and/or modify   *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This code is distributed in the hope that it will be useful, but      *
 *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
 *   General Public License for more details.                              *
 *                                                                         *
 *   A copy of the GNU General Public License is available on the World    *
 *   Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also      *
 *   obtain it by writing to the Free Software Foundation,                 *
 *   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.        *
 *                                                                         *
 */
 -->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
    <meta content="text/html; charset=UTF-8" http-equiv="content-type">
    <title>Тестовое задание.</title>
      <script type="text/javascript" src="jscript.js"></script>
      <script type="text/javascript">
         function reqtitle(req) {

              document.getElementById('ftitle').innerHTML = req.responseText;

         }

         function chktitlef(k) {

              var cmbox = document.getElementById('favparams_'+k);
              ajax('chktitle.php?c1='+cmbox.options[cmbox.selectedIndex].value, 'GET', null, reqtitle);

         }

         function GetAnswer(req) {

             var response = req.responseText.split('|');
             var res = '';

             for (var i=0;i<=response[0]-1;i++) {

                 var test = response[1].split('*');
                 res=res+'<select id="favparams_'+i+'" name="param_'+i+'" onclick="chktitlef('+i+'); return false;">'+test[i]+'</select><button type="submit" name="delfav" value="Delete" onclick="deletef('+i+'); return false;">Delete</button><br>';                
                  
             }
             document.getElementById('answer').innerHTML = res;         

         }

         function makeRequest() {
              ajax('parse_file.php?file='+window.frames["upload_target"].document.body.innerHTML, 'GET', null, GetAnswer);
         }

         function reqdelfav(req) {

              var response = req.responseText.split('|');

              document.getElementById('favparams_'+response[1]).innerHTML = response[0];

         }

         function deletef(i) {

              var cmbox_1 = document.getElementById('favparams_'+i);
 
              ajax('del.php?favpath='+cmbox_1.options[cmbox_1.selectedIndex].value+'&c='+i, 'GET', null, reqdelfav);

         }
      </script>
  </head>
  <body>
  <div>
     <span>
		 Conditions: use ajax and any framework if you like.
		 Test: Upload html file to server and get all http links from it. 
		 Sort them by domain and write in database(e.x. MySQL). 
		 Under this form should be a statistic by domain. 
		 Each domain group should be in their own drop-down list.
         If the link not needed it should be deleted.
     </span>
  </div>
  <fieldset>
     <legend>Upload HTML file:</legend>
       <form method="POST" target="upload_target" action="upload.php" enctype="multipart/form-data">
          <input name="fupload" type="file">
          <input name="submit" type="submit" value="Upload">           
          <iframe id="upload_target" name="upload_target" src="#" style="width:100;height:100;border:0px solid #fff;"></iframe>
       </form>
       <form method="POST" action="">
          <input name="submit" type="submit" value="Show" onclick="makeRequest(); return false;">
       </form>
  </fieldset>
  <form id="deletion" method="POST" action="">  
    <fieldset>
      <legend>Statistic:</legend>
        <div id="answer">
        </div><br>
        <span>Title of choosen page: </span>
        <div id="ftitle">
        </div>
    </fieldset>
  </form>
  </body>
</html>
